from django.db import models
from utils.BaseModel import BaseModel
# Create your models here.

class CateModel(BaseModel):
    name=models.CharField(max_length=32,verbose_name="课程名称")
    parent=models.ForeignKey("self",on_delete=models.CASCADE,verbose_name="父级分类",related_name="son",null=True)
    recommend=models.BooleanField(default=False,verbose_name="是否推荐")
    ishot=models.BooleanField(default=False,verbose_name="是否热门")
    isgood=models.BooleanField(default=False,verbose_name="是否精品")
    class Meta:
        db_table="fgcate"

    def __str__(self):
        return self.name





class TeacherModel(BaseModel):
    name = models.CharField(max_length=32, verbose_name="老师名称")
    img=models.CharField(verbose_name="老师头像",max_length=200)
    jobtitle=models.CharField(verbose_name="讲师职称",max_length=20)
    intro=models.TextField(verbose_name="讲师简介")
    sales=models.IntegerField(default=0,verbose_name="销量")

    class Meta:
        db_table='fgteacher'


    def __str__(self):
        return self.name


# 课程难度
level_choices=(
    ('1','初级'),
    ('2','中级'),
    ('3','高级')
)

class CourseModel(BaseModel):
    name=models.CharField(max_length=50,verbose_name='课程名称')
    image=models.CharField(max_length=200,blank=True,null=True,verbose_name='课程图片')
    price=models.DecimalField(max_digits=8,decimal_places=2,verbose_name="课程价格")
    category=models.ForeignKey(CateModel,on_delete=models.CASCADE,verbose_name='课程分类')
    teacher=models.ForeignKey(TeacherModel,on_delete=models.CASCADE,verbose_name="授课老师")
    intro=models.TextField(verbose_name='课程简介')
    level=models.CharField(max_length=10,choices=level_choices,verbose_name='课程难度')
    numbers=models.IntegerField(default=0,verbose_name='课程人数')
    is_home=models.BooleanField(default=True,verbose_name='是否首页推荐')
    video=models.CharField(verbose_name="视频",max_length=200,default="http://127.0.0.1:8000/uploads/course/1.mp4")

    class Meta:
        db_table='fgcourse'

    def __str__(self):
        return  self.name







